<template>
  <!-- 文章卡片 -->
  <div>
    <el-card class="my-card" @click.native="toTextDetail">
      <div slot="header" class="card-header">
        <div style="display: flex">
          <span style="flex: 3">{{ knowledge.title }}</span>
          <span style="flex: 1">{{ formatDate(new Date()) }}</span>
        </div>
      </div>
      <div class="card-body">
        <div>
          <el-image
            style="width: 100px; height: 100px"
            :src="knowledge.cover"
            fit="fit"
          ></el-image>
        </div>

        <div class="card-text">{{ knowledge.brief }}</div>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "KnowledgeCard",
  props: ["knowledge"],
  data() {
    return {
      title: "文章标题", //文章标题
      date: new Date(), //文章发布时间
      imgUrl:
        "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg", //文章图片
      text: "在婚恋亲密关系的心理咨询中，我发现伴侣关系常存在三种模式。在婚恋亲密关系的心理咨询中，我发现伴侣关系常存在三种模式。在婚恋亲密关系的心理咨询中，我发现伴侣关系常存在三种模式。在婚恋亲密关系的心理咨询中，我发现伴侣关系常存在三种模式。", //文章简介
      textUrl: "/", //文章链接
    };
  },
  computed: {},
  methods: {
    //进入知识详情
    toTextDetail() {
      this.$router.push({
        name: "KnowledgeDetail", //必须使用路由名称
        params: { id: this.knowledge.knowledgeid },
      });
    },
    formatDate(date) {
      date = this.date;
      const options = {
        year: "numeric",
        month: "2-digit",
        day: "2-digit",
        // hour: "2-digit",
        // minute: "2-digit",
        // second: "2-digit",
      };
      return new Intl.DateTimeFormat("zh-CN", options).format(date);
    },
  },
};
</script>

<style scoped>
.card-header {
  height: 25px;
}

.my-card {
  width: 100%;
  height: 100%;
}
.card-body {
  display: flex;
  align-items: center;
  /* flex-wrap:wrap; */
}

.card-text {
  padding-left: 20px;
  flex-wrap: wrap;
}
</style>